package payrechargelogic

import (
	"context"
	model "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/recharge"
	schema "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/schema/recharge"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RechargeVipLevelCreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRechargeVipLevelCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RechargeVipLevelCreateLogic {
	return &RechargeVipLevelCreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// RechargeVipLevelCreate vip充值等级Create
func (l *RechargeVipLevelCreateLogic) RechargeVipLevelCreate(in *rpc.RechargeVipLevelCreateRequest) (*rpc.CommonResponse, error) {
	var commonResp rpc.CommonResp
	data := schema.RechargeVip{
		Level:          in.Level,
		RechargeTimes:  in.Times,
		RechargeAmount: in.Amount,
	}
	err := model.NewRechargeVipModel(l.ctx, l.svcCtx.Db).InsertRechargeVip(&data)
	if err != nil {
		commonResp.Code = xerrors.DBError
		commonResp.Message = "Database operation error"
		return &rpc.CommonResponse{CommonResp: &commonResp}, err
	}
	return &rpc.CommonResponse{}, nil
}
